package com.zenaprod.zenda.bag;


import com.zenaprod.framework.log.ZLog;
import com.zenaprod.twodcore.graphic.element.Element;

public class Box {
    private static int id = 0;

    private int boxId;
    private Element element;
    private int elementCount;
    private int row;
    private int column;


    public Box(int row, int column) {
        this.row = row;
        this.column = column;
        elementCount = 0;

        System.out.println("New box row: " + row + " column: " + column);
    }

    public boolean contains(Element element) {
        return element.equals(element);
    }

    public void addElement(Element element) {
        if (isEmpty()) {
            this.element = element;
        } else if (!this.element.equals(element)) {
            ZLog.e("Box contains " + this.element.getName() + ". Can't add " + element.getName());
            return;
        }
        elementCount++;
    }

    public void remove(Element element) {
        if (isEmpty()) {
            ZLog.e("Can't remove element " + element.getName() + ". Box is empty.");
            return;
        }
        if (!this.element.equals(element)) {
            ZLog.e("Box contains " + this.element.getName() + ". Can't remove " + element.getName());
            return;
        }
        elementCount--;
        if (elementCount == 0) {
            clear();
        }
    }

    public boolean isEmpty() {
        return elementCount == 0;
    }

    public void clear() {
        element = null;
        elementCount = 0;
    }


    public int getColumn() {
        return column;
    }

    public int getRow() {
        return row;
    }
}
